package game.resources;

import game.structures.Point;

public class Collision {
	public static boolean isColliding(Point point, int id) {
		
		
		switch(id) {
		case -1:
			return false;
		case 0:
			return true;
		case 1:
			if (point.getY() % 128.0f >= 64.0f)
				return true;
			return false;
		case 2:
			if (point.getY() % 128.0f <= 64.0f)
				return true;
			return false;
		case 3:
			if (point.getX() % 128.0f <= 64.0f)
				return true;
			return false;
		case 4:
			if (point.getX() % 128.0f >= 64.0f)
				return true;
			return false;
		case 5:
			if (point.getY() % 128.0f > 128.0f - (point.getX() % 128.0f / 2) )
				return true;
			return false;
		case 6:
			if (point.getY() % 128.0f > 128.0f - (point.getX() % 128.0f / 2 + 64) )
				return true;
			return false;
		case 7:
			if (point.getY() % 128.0f > 128.0f - (point.getX() % 128.0f) )
				return true;
			return false;
		case 8:
			//System.out.println((point.getY() % 128)+ " " + getQuadIIICircleCoordinate(point.getX(), false));
			if (point.getY() % 128  > getQuadIIICircleCoordinate(point.getX(), false) )
				return true;
			return false;
		case 9:
			//System.out.println((point.getY() % 128)+ " " + getQuadIIICircleCoordinate(point.getX(), false));
			if (point.getY() % 128 + 128 > getQuadIIICircleCoordinate(point.getX(), false) )
				return true;
			return false;
		case 10:
			//System.out.println((point.getY() % 128)+ " " + getQuadIIICircleCoordinate(point.getX(), true));
			if (point.getY() % 128 + 128 > getQuadIIICircleCoordinate(point.getX(), true))
				return true;
			return false;
		case 11:
			if (point.getY() % 128  > getQuadIInnerCircleCoordinate(point.getX(), false) )
				return true;
			return false;
		case 12:
			if (point.getY() % 128 > getQuadIInnerCircleCoordinate(point.getX(), true))
				return true;
			return false;
		case 13:
			if (point.getY() % 128 + 128 > getQuadIInnerCircleCoordinate(point.getX(), true))
				return true;
			return false;
		}
		
		
		return false;
	}
	
	private static float getQuadICircleCoordinate(float x, boolean offset) {
		return (float) (Math.pow(-Math.pow(x % 128 + (offset ? 128 : 0f), 2) + Math.pow(256, 2), 1/2));
	}
	
	private static float getQuadIICircleCoordinate(float x, boolean offset) {
		return (float) (Math.pow(-Math.pow(x  % 128 + (offset ? 128 : 0f) - 1, 2) + 1, 1/2));
	}
	
	private static float getQuadIIICircleCoordinate(float xInput, boolean offset) {
		float x = xInput % 128f;
		if(offset)
			x = (x + 128f)/ 256f;
		else
			x /= 256f;
		//System.out.println(x);
		//System.out.println(Math.sqrt(-Math.pow( (x - 1), 2) + 1) * 256f);
		return (float) (Math.sqrt(-Math.pow( (x - 1), 2) + 1) * 256f);
	}
	
	private static float getQuadIVCircleCoordinate(float x, boolean offset) {
		return (float) (-Math.pow(-Math.pow(x  % 128 + (offset ? 128 : 0f) , 2) + Math.pow(256, 2), 1/2) + 256);
	}
	
	private static float getQuadIInnerCircleCoordinate(float xInput, boolean offset) {
		float x = xInput % 128f;
		if(offset)
			x = (x + 128f)/ 256f;
		else
			x /= 256f;
		//System.out.println(x);
		//System.out.println(Math.sqrt(-Math.pow( (x - 1), 2) + 1) * 256f);
		//-sqrt(-(x ) ^ 2 + 1) + 1
		return (float) (-Math.sqrt(-Math.pow(x, 2) + 1)+1) * 256f;
	}
}
